package com.hualan.sfzy.service.announcementConsult.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hualan.sfzy.constant.CommonConstant;
import com.hualan.sfzy.entity.announcementConsult.AnnouncementConsult;
import com.hualan.sfzy.mapper.announcementConsult.AnnouncementConsultMapper;
import com.hualan.sfzy.service.announcementConsult.AnnouncementConsultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class AnnouncementConsultServiceImpl implements AnnouncementConsultService {

    @Autowired
    private AnnouncementConsultMapper announcementConsultMapper;

    @Override
    public int add(AnnouncementConsult announcementConsult) {
        return announcementConsultMapper.insert(announcementConsult);
    }

    @Override
    public int remove(Integer id) {
        return announcementConsultMapper.delete(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return announcementConsultMapper.deleteBatch(ids);
    }

    @Override
    public int edit(AnnouncementConsult announcementConsult) {
        return announcementConsultMapper.update(announcementConsult);
    }

    @Override
    public AnnouncementConsult findById(Integer id) {
        return announcementConsultMapper.selectById(id);
    }

    @Override
    public Map<String, Object> findByPage(Integer pageNum, Integer pageSize, AnnouncementConsult announcementConsult) {
        PageHelper.startPage(pageNum, pageSize);
        List<AnnouncementConsult> list = announcementConsultMapper.select(announcementConsult);
        PageInfo<AnnouncementConsult> pageInfo = new PageInfo<>(list);
        Map<String, Object> map = new HashMap<>();
        // map存储当前页数据、总页数、总记录数
        map.put(CommonConstant.PAGE_LIST, list);
        map.put(CommonConstant.PAGE_TOTAL, pageInfo.getPages());
        map.put(CommonConstant.TOTAL, pageInfo.getTotal());
        return map;
    }

    @Override
    public List<AnnouncementConsult> find() {
        return announcementConsultMapper.select(null);
    }
}
